package org.example.utlis;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import org.example.App;

import java.util.Optional;

public class FXUtils {
    public static void setBackground(Pane pane, String webColor) {
        pane.setBackground(new Background(new BackgroundFill(Color.web(webColor), null, null)));
    }
    public static void setBackground(Region region, String webColor) {
        region.setBackground(new Background(new BackgroundFill(Color.web(webColor), null, null)));
    }

    public static void initSimpleDialog(String title, String remind) {
        initSimpleDialog(title, remind, null, null);
    }

    public static void initSimpleDialog(String title, String remind, Runnable okListener, Runnable cancelListener) {
        Platform.runLater(() -> {
            Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
            alert.setTitle(title);
            alert.setHeaderText(null);
            alert.setContentText(remind);

            App.useJMetro(alert.getDialogPane().getScene());

            Optional<ButtonType> result = alert.showAndWait();
            if (result.get() == ButtonType.OK) {
                if (okListener != null) new Thread(okListener).start();
            } else {
                if (cancelListener != null) new Thread(cancelListener).start();
            }
        });
    }
}
